﻿// =================================================================== 
// 项目说明
//====================================================================
// 
// 文件： SYS_OPERATOR_ROLE.cs
// 项目名称：


// 创建时间：2013/3/19
// 负责人：
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using CommonLib.Model;
using CommonLib.IDAL;


//注意：该文件自动生成，一般请不要手工修改。




namespace MSSQLDAL
{
    /// <summary>
    /// 数据层实例化接口类 .
    /// </summary>
    public partial class SYS_OPERATOR_ROLEDAL : ISYS_OPERATOR_ROLEDAL
    {
		
		 #region 变量声明（For update 和 Insert 时）
		// 声明静态变量 
		private const string PARA_USER_ID =  "@USER_ID";
		private const string PARA_MASTER_ID =  "@MASTER_ID";
		private const string PARA_NOTES =  "@NOTES";

		private const string SQL_UPDATE = "UPDATE SYS_OPERATOR_ROLE SET  USER_ID= @USER_ID, MASTER_ID= @MASTER_ID, NOTES= @NOTES  WHERE USER_ID = @USER_ID and MASTER_ID = @MASTER_ID ";
		private const string SQL_INSERT = "INSERT INTO SYS_OPERATOR_ROLE(USER_ID, MASTER_ID, NOTES ) values ( @USER_ID, @MASTER_ID, @NOTES ) ";
		#endregion
		
		// 查询数据的sql串




		private string TableString;
		
		#region 构造函数




		/// <summary>
		/// ??????
		/// </summary>
		public SYS_OPERATOR_ROLEDAL()
		{
			if (QueryDataString == "")
                TableString = "SYS_OPERATOR_ROLE SQL_A";
            else
                TableString = "(" + QueryDataString + ") SQL_A";
		}
		#endregion

        //-----------实例化接口函数-----------
		
		//------------增删改函数------------------- 
		
		#region Add 向数据库中插入一条新记录。




		/// <summary>
		/// 向数据库SYS_OPERATOR_ROLE中插入一条新记录。




		/// </summary>
		/// <param name="_SYS_OPERATOR_ROLEModel">SYS_OPERATOR_ROLE??</param>
		/// <returns>影响的行数</returns>
		public int Add(CommonLib.Model.SYS_OPERATOR_ROLE _SYS_OPERATOR_ROLEModel)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter(PARA_USER_ID, SqlDbType.VarChar), 
				new SqlParameter(PARA_MASTER_ID, SqlDbType.Int), 
				new SqlParameter(PARA_NOTES, SqlDbType.VarChar)
			};			
			
			 _param[0].Value =  _SYS_OPERATOR_ROLEModel.USER_ID;
			 _param[1].Value =  _SYS_OPERATOR_ROLEModel.MASTER_ID;
			 _param[2].Value =  _SYS_OPERATOR_ROLEModel.NOTES;

			
			//  返回
			return (int)SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, SQL_INSERT, _param);


		}
		#endregion
		
		#region Add 向数据库中插入一条新记录。带事务
		/// <summary>
		/// 向数据库SYS_OPERATOR_ROLE中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_SYS_OPERATOR_ROLEModel">SYS_OPERATOR_ROLE实体</param>
		/// <returns>影响的行数</returns>
		public int Add(DBTransaction dbTrans,CommonLib.Model.SYS_OPERATOR_ROLE _SYS_OPERATOR_ROLEModel)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter(PARA_USER_ID, SqlDbType.VarChar), 
				new SqlParameter(PARA_MASTER_ID, SqlDbType.Int), 
				new SqlParameter(PARA_NOTES, SqlDbType.VarChar)
			};	
			
			 _param[0].Value =  _SYS_OPERATOR_ROLEModel.USER_ID;
			 _param[1].Value =  _SYS_OPERATOR_ROLEModel.MASTER_ID;
			 _param[2].Value =  _SYS_OPERATOR_ROLEModel.NOTES;

			
			//  返回
			return (int)SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, SQL_INSERT, _param);
		}
		#endregion
		
		#region	Update 向数据表更新一条记录。	
		/// <summary>
		/// 向数据表SYS_OPERATOR_ROLE更新一条记录。




		/// </summary>
		/// <param name="_SYS_OPERATOR_ROLEModel">_SYS_OPERATOR_ROLEModel</param>
		/// <returns>影响的行数</returns>
		public int Update(CommonLib.Model.SYS_OPERATOR_ROLE _SYS_OPERATOR_ROLEModel)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter(PARA_USER_ID, SqlDbType.VarChar), 
				new SqlParameter(PARA_MASTER_ID, SqlDbType.Int), 
				new SqlParameter(PARA_NOTES, SqlDbType.VarChar)
			};	
			
			 _param[0].Value =  _SYS_OPERATOR_ROLEModel.USER_ID;
			 _param[1].Value =  _SYS_OPERATOR_ROLEModel.MASTER_ID;
			 _param[2].Value =  _SYS_OPERATOR_ROLEModel.NOTES;
			
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, SQL_UPDATE, _param);
		}
		#endregion
		
		#region	Update 向数据表更新一条记录。带事务	
		/// <summary>
		/// 向数据表SYS_OPERATOR_ROLE更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_SYS_OPERATOR_ROLEModel">_SYS_OPERATOR_ROLEModel</param>
		/// <returns>影响的行数</returns>
		public int Update(DBTransaction dbTrans,CommonLib.Model.SYS_OPERATOR_ROLE _SYS_OPERATOR_ROLEModel)
		{
           // 声明参数数组并赋值




		    SqlParameter[] _param=
			{
				new SqlParameter(PARA_USER_ID, SqlDbType.VarChar), 
				new SqlParameter(PARA_MASTER_ID, SqlDbType.Int), 
				new SqlParameter(PARA_NOTES, SqlDbType.VarChar)
			};		
			
			 _param[0].Value =  _SYS_OPERATOR_ROLEModel.USER_ID;
			 _param[1].Value =  _SYS_OPERATOR_ROLEModel.MASTER_ID;
			 _param[2].Value =  _SYS_OPERATOR_ROLEModel.NOTES;
			

			
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, SQL_UPDATE, _param);
		}
		#endregion
		
		#region	Delete 根据主键，删除数据表中的一条记录	
		/// <summary>
		/// 根据主键，删除数据表SYS_OPERATOR_ROLE中的一条记录




		/// </summary>
	    /// <param name="uSER_ID">uSER_ID</param>
		/// <returns>影响的行数</returns>
		public int Delete(string uSER_ID, int mASTER_ID)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter("@uSER_ID", SqlDbType.VarChar), 
				new SqlParameter("@mASTER_ID", SqlDbType.Int)
			};				
			_param[0].Value = uSER_ID;
			_param[1].Value = mASTER_ID;
			
			string sqlStr="delete from SYS_OPERATOR_ROLE where  USER_ID=@uSER_ID and MASTER_ID=@mASTER_ID";
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, sqlStr, _param);;
		}
		#endregion
		
		#region	Delete 根据主键，删除数据表中的一条记录 带事务




		/// <summary>
		/// 根据主键，删除数据表SYS_OPERATOR_ROLE中的一条记录 带事务




		/// <param name="sp">事务对象</param>
	    /// <param name="USER_ID">uSER_ID</param>
		/// <returns>影响的行数</returns>
		public int Delete(DBTransaction dbTrans,string uSER_ID, int mASTER_ID)
		{
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter("@uSER_ID", SqlDbType.VarChar), 
				new SqlParameter("@mASTER_ID", SqlDbType.Int)
			};				
			_param[0].Value = uSER_ID;
			_param[1].Value = mASTER_ID;

			string sqlStr="delete from SYS_OPERATOR_ROLE where  USER_ID=@uSER_ID and MASTER_ID=@mASTER_ID";
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, sqlStr,_param);;

		}
		#endregion
		
		#region	DeleteFK 根据条件串，删除数据表中的N条记录	
		/// <summary>
		/// 根据条件串，删除数据表SYS_OPERATOR_ROLE中的N条记录




		/// </summary>
	    /// <param name="sWhere">条件串</param>
		/// <returns>影响的行数</returns>
		public int DeleteFK(string sWhere)
		{
			string  sqlStr="delete from SYS_OPERATOR_ROLE";
			if (sWhere.Length>0)
				sqlStr += " where "+sWhere;
			return SqlHelper.ExecuteNonQuery(Conn.SqlConnStr, CommandType.Text, sqlStr);
		}
		#endregion
		
		#region	DeleteFK 删除数据表中的一条记录,带事务	
		/// <summary>
		/// 删除数据表SYS_OPERATOR_ROLE中的一条记录,带事务




		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="sWhere">条件串</param>
		/// <returns>影响的行数</returns>
		public int DeleteFK(DBTransaction dbTrans,string sWhere)
		{
			string  sqlStr="delete from SYS_OPERATOR_ROLE";
			if (sWhere.Length>0)
				sqlStr += " where "+sWhere;
			return SqlHelper.ExecuteNonQuery(dbTrans.sql_trans, CommandType.Text, sqlStr);
		}
		
		#endregion
		
		
		//------------获取数据及模型函数




		
		#region Exists 检测是否存在该主键
		/// <summary>
        /// 检测是否存在该主键
        /// </summary>
        /// <param name="string uSER_ID, int mASTER_ID" 主键列表</param>
        /// <returns>是/否</returns>
		public bool Exists(string uSER_ID, int mASTER_ID)
		{
			
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter("@uSER_ID", SqlDbType.VarChar), 
				new SqlParameter("@mASTER_ID", SqlDbType.Int)
			};				
			_param[0].Value = uSER_ID;
			_param[1].Value = mASTER_ID;
			
            string sqlStr="select Count(*) from SYS_OPERATOR_ROLE where  USER_ID=@uSER_ID and MASTER_ID=@mASTER_ID and USER_ID=@uSER_ID and MASTER_ID=@mASTER_ID";
						
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

		#endregion

		#region GetModel 根据主键ID,得到数据实体
        /// <summary>
		/// 根据主键ID,得到 sys_operator_role 数据实体
		/// </summary>
		/// <param name="string uSER_ID, int mASTER_ID" 主键列表</param>
		/// <returns>sys_operator_role 数据实体</returns>
		public CommonLib.Model.SYS_OPERATOR_ROLE GetModel(string uSER_ID, int mASTER_ID )
		{
			CommonLib.Model.SYS_OPERATOR_ROLE _obj=null;
			// 声明参数数组并赋值




			SqlParameter[] _param=
			{
				new SqlParameter("@uSER_ID", SqlDbType.VarChar), 
				new SqlParameter("@mASTER_ID", SqlDbType.Int)
			};				
			_param[0].Value = uSER_ID;
			_param[1].Value = mASTER_ID;
			
			string sqlStr="select * from SYS_OPERATOR_ROLE where  USER_ID=@uSER_ID and MASTER_ID=@mASTER_ID";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(Conn.SqlConnStr,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=PopulateSYS_OPERATOR_ROLEModelFromDr(dr);
				}
			}
			return _obj;
		}
		#endregion
		
		#region ----根据DataRow,得到 数据实体
		/// <summary>
		/// 得到  sys_operator_role 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>sys_operator_role 数据实体</returns>
		public CommonLib.Model.SYS_OPERATOR_ROLE PopulateSYS_OPERATOR_ROLEModelFromDr(DataRow row)
		{
			CommonLib.Model.SYS_OPERATOR_ROLE Obj = new CommonLib.Model.SYS_OPERATOR_ROLE();
			if(row!=null)
			{
				Obj.USER_ID =  row["USER_ID"].ToString();
				Obj.MASTER_ID = (( row["MASTER_ID"])==DBNull.Value)?0:Convert.ToInt32( row["MASTER_ID"]);
				Obj.NOTES =  row["NOTES"].ToString();
			}
			else
			{
				return null;
			}
			return Obj;
		}
		#endregion
		
		#region ----根据IDataReader,得到 数据实体
        /// <summary>
		/// 得到  sys_operator_role 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>sys_operator_role 数据实体</returns>
		public CommonLib.Model.SYS_OPERATOR_ROLE PopulateSYS_OPERATOR_ROLEModelFromDr(IDataReader dr)
		{
			CommonLib.Model.SYS_OPERATOR_ROLE Obj = new CommonLib.Model.SYS_OPERATOR_ROLE();
			
				Obj.USER_ID =  dr["USER_ID"].ToString();
				Obj.MASTER_ID = (( dr["MASTER_ID"])==DBNull.Value)?0:Convert.ToInt32( dr["MASTER_ID"]);
				Obj.NOTES =  dr["NOTES"].ToString();
			
			return Obj;
		}
		#endregion
///
		#region GetNewID 通过种子得到唯一ID,对单主键有效单，如果该表为多主键，则返回第一主键
		/// <summary>
        ///  通过种子得到唯一ID,对单主键有效单，如果该表为多主键，则返回第一主键
        /// </summary>
        /// <param name="uSER_ID">uSER_ID</param>
        /// <returns>string</returns>
		public int GetNewID()
		{
			return  DBCommon.GetNewIDForTable("SYS_OPERATOR_ROLE","SYS_OPERATOR_ROLE","");
		}
		#endregion
///
		#region	GetMaxID 得到最大ID	
		/// <summary>
		/// 得到最大ID
		/// </summary>
        /// <param name="uSER_ID">uSER_ID</param>
        /// <returns>string</returns>
		public int GetMaxID()
		{
			return  0;
		}
		#endregion
		
		#region	GetList 得到数据表指定字段列表的所有记录，可排序，
		/// <summary>
		/// 得到数据表SYS_OPERATOR_ROLE所有记录，可排序




		/// </summary>
        /// <param name="sWhere">条件字符串</param>
        /// <param name="sOder">排序字段</param>
		/// <returns>DataSet</returns>
		public DataSet GetList(string sWhere, string sOder)
		{
			string	sqlStr="select * from "+TableString;
				
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			if (sOder.Length > 0)
				sqlStr += " order by " + sOder;
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion

		#region	GetListFS 得到数据表指定字段列表的所有记录，可排序，加工作流状态字段




		/// <summary>
		/// 得到数据表SYS_OPERATOR_ROLE所有记录，可排序，加工作流状态字段




		/// </summary>
        /// <param name="FlowProcessId">流程ID</param>
        /// <param name="sWhere">条件字符串</param>
        /// <param name="sOder">排序字段</param>
		/// <returns>DataSet</returns>
		public DataSet GetListFS(string FlowProcessId, string sWhere, string sOder)
		{
			string	sqlStr="select SQL_A.*, isnull(SQL_B.work_state,'未发送') work_state from "+TableString+" left join view_wfInstance_state SQL_B on SQL_a.work_id=SQL_b.work_id";
				
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			if (sOder.Length > 0)
				sqlStr += " order by " + sOder;
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion


		#region GetPageList 根据条件和页号得到某页的记录集,+排序
		/// <summary>
		/// 根据条件和页号得到某页的记录集,+排序
		/// </summary>
        /// <param name="iPageSize">每页记录数</param>
		/// <param name="iPageIndex">页号</param>
		/// <param name="sWhere">条件字符串</param>
		/// <param name="sOder">排序字段</param>
        /// <returns>DataSet</returns>
		public DataSet GetPageList(int iPageSize,int iPageIndex, string sWhere, string sOder)
		{
			if (sOder.Length <=0)
				sOder = "USER_ID";
				
			string	sqlStr="select * from (select ROW_NUMBER() OVER(order by "+sOder+" ) as row, * from "+TableString;
			
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			sqlStr += ") SQL1 where row between "+ Convert.ToString(iPageSize*(iPageIndex-1)+1) +" and "+Convert.ToString(iPageSize*iPageIndex);
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion		

		#region GetPageListFS 根据条件和页号得到某页的记录集,+排序，加工作流状态字段




		/// <summary>
		/// 根据条件和页号得到某页的记录集,+排序，加工作流状态字段




		/// </summary>
        /// <param name="FlowProcessId">流程ID</param>
        /// <param name="iPageSize">每页记录数</param>
		/// <param name="iPageIndex">页号</param>
		/// <param name="sWhere">条件字符串</param>
		/// <param name="sOder">排序字段</param>
        /// <returns>DataSet</returns>
		public DataSet GetPageListFS(string FlowProcessId, int iPageSize,int iPageIndex, string sWhere, string sOder)
		{
			if (sOder.Length <=0)
				sOder = "USER_ID";
				
			string	sqlStr="select * from (select ROW_NUMBER() OVER(order by "+sOder+" ) as row, SQL_A.*,isnull(SQL_B.work_state,'未发送') work_state from "+TableString+" left join view_wfInstance_state SQL_B on sql_a.work_id=sql_b.work_id";
			
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
			sqlStr += ") SQL1 where row between "+ Convert.ToString(iPageSize*(iPageIndex-1)+1) +" and "+Convert.ToString(iPageSize*iPageIndex);
			return SqlHelper.ExecuteDataset(Conn.SqlConnStr,CommandType.Text,sqlStr);
		}
		#endregion		
		
		
		#region GetRecorderRowNum 判断某条记录所在的行号
		/// <summary>
		/// 判断某条记录所在的行号，调用者自己计算页号和行号
		/// </summary>
        /// <param name="sWhere">记录显示的条件</param>
        /// <param name="sOder">排序条件</param>
        /// <param name="iPageSize">每页记录数</param>
		/// <param name="主键列表">主键列表，需定位记录的键值</param>
        /// <returns>int 页码</returns>
		public int GetRecorderRowNum(string sWhere, string sOder, int iPageSize, string uSER_ID, int mASTER_ID)
		{
			if (sOder.Length <=0)
				sOder = "USER_ID";
				
			// 声明参数数组并赋值



			SqlParameter[] _param=
			{
				new SqlParameter("@uSER_ID", SqlDbType.VarChar), 
				new SqlParameter("@mASTER_ID", SqlDbType.Int)
			};				
			_param[0].Value = uSER_ID;
			_param[1].Value = mASTER_ID;
			
			string	sqlStr="select row from (select ROW_NUMBER() OVER(order by "+sOder+" ) as row, uSER_ID, mASTER_ID from "+TableString;
			
			if (sWhere.Length > 0)
				sqlStr += " where " + sWhere;
				
			sqlStr = sqlStr + ") SQL1 where  USER_ID=@uSER_ID and MASTER_ID=@mASTER_ID";
			return Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr,_param));
		}
		#endregion
		
						
		#region GetRecorderCount 得到符合条件记录集的记录条数
		/// <summary>
		/// 得到符合条件记录集的记录条数
		/// </summary>
        /// <param name="FlowProcessId">流程ID</param>
		/// <param name="sWhere">条件字符串</param>
        /// <returns>int 记录数</returns>
		public int GetRecorderCount(string FlowProcessId, string sWhere)
		{
			string sqlStr ="";
			
			if (FlowProcessId.Length > 0)
            	sqlStr="select Count(*) from "+TableString+" left join view_wfInstance_state SQL_B on SQL_a.work_id=SQL_b.work_id";
			else
				sqlStr="select Count(*) from "+TableString;
				
			if (sWhere.Length>0)
				sqlStr += " where " + sWhere;
						
            return Convert.ToInt32(SqlHelper.ExecuteScalar(Conn.SqlConnStr,CommandType.Text,sqlStr));
		}
		#endregion				
		
		#region----------自定义实例化接口函数----------
		#endregion
    }
}
